package cn.tmall.web.cms;

import cn.tmall.IFileService;
import cn.tmall.commons.constant.factory.PageFactory;
import cn.tmall.commons.controller.BaseController;
import cn.tmall.commons.enums.Permission;
import cn.tmall.commons.utils.StringUtil;
import cn.tmall.commons.utils.factory.Page;
import cn.tmall.entity.system.FileInfo;
import cn.tmall.front.Rets;
import cn.tmall.query.SearchFilter;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fileMgr")
public class FileMgrController extends BaseController {

    @Reference
    private IFileService fileService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @RequiresPermissions(value = {Permission.FILE})
    public Object list(@RequestParam(required = false) String originalFileName
    ) {
        Page<FileInfo> page = new PageFactory<FileInfo>().defaultPage();
        if (StringUtil.isNotEmpty(originalFileName)) {
            page.addFilter(SearchFilter.build("originalFileName", SearchFilter.Operator.LIKE, originalFileName));
        }
        page = fileService.queryPage(page);
        return Rets.success(page);
    }
}
